import { type NextRequest, NextResponse } from "next/server"

export async function GET(request: NextRequest) {
  try {
    const searchParams = request.nextUrl.searchParams
    const userId = searchParams.get("userId")
    const page = searchParams.get("page") ? Number.parseInt(searchParams.get("page")!) : 1
    const limit = searchParams.get("limit") ? Number.parseInt(searchParams.get("limit")!) : 20

    // 模拟数据
    const albums = Array.from({ length: 15 }, (_, i) => ({
      id: i + 1,
      title: `Album Title ${i + 1}`,
      artist: `Artist ${(i % 5) + 1}`,
      releaseDate: `202${i % 3}-0${(i % 9) + 1}-0${(i % 9) + 1}`,
      cover: `/placeholder.svg?height=300&width=300&text=Album+${i + 1}`,
      songCount: 10 + i,
    }))

    return NextResponse.json({
      data: albums,
      pagination: {
        page,
        limit,
        total: 50,
        totalPages: Math.ceil(50 / limit),
      },
    })
  } catch (error) {
    console.error("Error fetching user liked albums:", error)
    return NextResponse.json({ error: "Failed to fetch user liked albums" }, { status: 500 })
  }
}

export async function POST(request: NextRequest) {
  try {
    const body = await request.json()
    const { albumId } = body

    return NextResponse.json({
      success: true,
      message: `Album ${albumId} added to favorites`,
    })
  } catch (error) {
    console.error("Error adding album to favorites:", error)
    return NextResponse.json({ error: "Failed to add album to favorites" }, { status: 500 })
  }
}

export async function DELETE(request: NextRequest) {
  try {
    const body = await request.json()
    const { albumId } = body

    return NextResponse.json({
      success: true,
      message: `Album ${albumId} removed from favorites`,
    })
  } catch (error) {
    console.error("Error removing album from favorites:", error)
    return NextResponse.json({ error: "Failed to remove album from favorites" }, { status: 500 })
  }
}

